package com.lksoft.bz.action;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.AbstractAction;

import com.lksoft.bz.Bz;

public class QuitAction extends AbstractAction implements WindowListener {
	private static final long serialVersionUID = 1972717971315611720L;
	
	private Bz bz;
	
	/**
	 * @param bz The program
	 */
	public QuitAction(Bz bz){
		super();
		this.bz = bz;
		
		putValue(MNEMONIC_KEY, KeyEvent.VK_Q);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		quit();
	}
	
	@Override
	public void windowClosing(WindowEvent e) {
		quit();
	}

	private void quit() {
		// Ask for save
		if( bz.askForSave() ){
			System.exit(0);
		}
	}

	@Override
	public void windowActivated(WindowEvent e) {}
	@Override
	public void windowClosed(WindowEvent e) {}
	@Override
	public void windowDeactivated(WindowEvent e) {}
	@Override
	public void windowDeiconified(WindowEvent e) {}
	@Override
	public void windowIconified(WindowEvent e) {}
	@Override
	public void windowOpened(WindowEvent e) {}
}
